<script src="/js/em/core-eqpt.js"></script>
<style type="text/css">
    .scrollTbody {
        overflow: auto;
        width: 100%;
    }

    .table {
        margin-bottom: 0 !important
    }

    .s-group, .t-group {
        display: none
    }
</style>
<div class="col-xs-8 padding5" id="base">
    <div class="shadow">
        <div class="title">
            <span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span><span>基本参数</span>
            <div class="pull-right">
                <button type="button" class="btn btn-info btn-xs" style="margin-right: 10px;"
                        onclick="showEqptLocation()">设备地理位置
                </button>
                <button type="button" class="btn btn-info btn-xs" style="margin-right: 10px;" id="returnBtn"
                        onclick="colseFullDialog()">返回
                </button>
            </div>
        </div>
        <table id="form-eqpt" class="table table-bordered" style="font-size:12px">
            <tr>
                <th class="col-xs-2">类型:</th>
                <td class="col-xs-2" name="TypeName"></td>
                <th class="col-xs-2">设备型号:</th>
                <td class="col-xs-2" name="Model"></td>
                <th class="col-xs-2">设备编号:</th>
                <td class="col-xs-2" name="EqptCode"></td>
            </tr>
            <tr>
                <th>生产厂家:</th>
                <td name="Manufacturer"></td>
                <th>出厂日期:</th>
                <td name="FactoryDate"></td>
                <th>首次安装日期:</th>
                <td name="FirstInstallDate"></td>
            </tr>
            <tr>
                <th>年检日期:</th>
                <td name="YearExamineDate"></td>
                <th>租赁时长(年):</th>
                <td name="Leaseduration"></td>
                <th>租赁费用到期日期:</th>
                <td name="CostEndDate"></td>
            </tr>
            <tr>
                <th>当前地址:</th>
                <td name="Curaddress" colspan="2"></td>
                <th>所属组织:</th>
                <td name="OrgName" colspan="2"></td>
            </tr>
            <tr>
                <th>标准节截面尺寸(米 x 米):</th>
                <td id="standard-section"></td>
                <th>附着架(套)</th>
                <td name="Attachment"></td>
                <th>标准节数(节)</th>
                <td><span style="height:22px;line-height:22px" name="StandardSection"></span>
                    <button onclick="showChangeLog()" class="btn btn-info btn-xs pull-right" style="margin-right:5px">
                        变更历史
                    </button>
                </td>
            </tr>
            <tr class="s-group">
                <th>传动方式:</th>
                <td name="DriveModel">普通</td>
                <th>安全器到期时间</th>
                <td name="SafetyDevice"></td>
                <th>额定运行速度(米/分钟):</th>
                <td name="RatedSpeed"></td>
            </tr>
            <tr class="t-group">
                <th>独立高度(米):</th>
                <td name="StandaloneHeight"></td>
                <th>最大高度(米):</th>
                <td name="MaxHeight"></td>
                <th>最大臂长(米):</th>
                <td name="MaxSweepLength"></td>
            </tr>
            <tr class="t-group">
                <th>力矩报警值(吨.米):</th>
                <td name="RatedMoment"></td>
                <th>额定力矩(吨.米):</th>
                <td name="RatedTorque"></td>
                <th>平衡块数(块)</th>
                <td name="BalanceBlock"></td>
            </tr>
            <tr>
                <th id="maxSlingLoad">载荷报警值(吨):</th>
                <td name="MaxSlingLoad"></td>
                <th id="cageLoad">额定载荷(吨):</th>
                <td name="CageLoad"></td>
            </tr>
        </table>
    </div>
</div>
<div class="col-xs-4 padding5" id="eqptOperation">
    <div class="shadow">
        <div class="title">
            <span class="glyphicon glyphicon-tasks" aria-hidden="true"></span><span>设备统计</span>
        </div>
        <div id="eqptOperationChar"></div>
    </div>
</div>
<div id='eqptWorkDiv' class='col-xs-12 padding0'></div>
<script type="text/javascript">
    var _eqptDialog = {
        popWidth: 650,
        btnShow: false
    }, _termL, _termR, myChart1, myChart2, num = 0, baseH = 0;
    var changeLog = {
        popWidth: 650,
        btnShow: false,
        src: "../eqpt/eqpt_changeLog_dialog.html",
        title: em.EqptCode + "标准节变更记录"
    };
    var mapDialog = {
        popWidth: 800,
        btnShow: false,
        src: "../eqpt/eqpt_location_dialog.html",
        title: em.EqptCode + "地理位置"
    };
    require.config({
        paths: {
            echarts: 'js/build/dist'
        }
    });
    if (em.EqptType == "升降机" || em.EqptType == 1) {
        em.EqptType = 1;
        var _termLStr = em.TermCode.substring(0, em.TermCode.indexOf("/"));
        _termL = _termLStr.substring(_termLStr.indexOf(")") + 1,
                _termLStr.length);
        var _termRStr = em.TermCode.substring(em.TermCode.indexOf("/") + 1,
                em.TermCode.length);
        _termR = _termRStr.substring(_termRStr.indexOf(")") + 1,
                _termRStr.length);
        initEqptData("../eqpt/eqpt_lifter_working.html");
    } else {
        em.EqptType = 2;
        initEqptData("../eqpt/eqpt_crane_working.html");
    }
    function initEqptData(eqptDivHtml) {
        callSvr("eqpt/getEqptBaseInfoById", {
            "eqptId": em.EqptId
        }, function (result) {
            $("#form-eqpt").jsonTotable(result);
            em.ETYPE = result.Type;
            if(result.standard_section_w && result.standard_section_h)$('#standard-section').text(result.standard_section_w+' x '+result.standard_section_h)
            if (result.TypeName == "升降机") {
                $(".s-group").show();
            } else {
                $(".t-group").show();
                $("#cageLoad").text("额定吊重(吨):");
                $("#maxSlingLoad").text("吊重报警值(吨):");
            }
            $("#eqptOperationChar").height($("#form-eqpt").height());
            require(['echarts', 'echarts/chart/bar'], function (ec) {
                myChart2 = ec.init(document.getElementById('eqptOperationChar'));
                operation();
            });
            $('#eqptWorkDiv').height($('#full-eqpt_detail').height() - $('#base').height() - 10);
            $('#eqptWorkDiv').load(eqptDivHtml);
        });

    }
    function listDialog(poptitle, src, carg) {
        _eqptDialog.title = poptitle;
        _eqptDialog.src = src;
        _carg = carg;
        Dialog = popWindowShow(_eqptDialog);
    }
    function showChangeLog() {
        Dialog = popWindowShow(changeLog);
    }
    function showEqptLocation() {
        Dialog = popWindowShow(mapDialog);
    }
    function operation() {
        //em.EqptType  1.升降机  2.塔机
        if (em.EqptType == 1) {
            callSvr("eqpt/getRunTimeList", {"eqptId": em.EqptId, "type": em.EqptType}, function (result) {
                var dateX = result.date;
                var dateY1 = result.runTime1;
                var dateY2 = result.runTime2;
                var option2 = {
                    title: {
                        text: '升降机运行时间统计',
                        textStyle: {
                            align: 'left',
                            fontFamily: '微软雅黑',
                            fontSize: 14
                        }
                    },
                    grid: {
                        x: '9%',
                        y: '15%',
                        x2: '7%',
                        y2: '15%'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        },
                        formatter: function (params, ticket, callback) {
                            var res = '日期:' + params[0].name;
                            var sum = 0.0;
                            for (var i = 0, l = params.length; i < l; i++) {
                                res += '<br/>' + params[i].seriesName + ' : '
                                        + params[i].value + '小时';
                                sum += params[i].value;
                            }
                            res += '<br/>设备总运行时长为:' + sum.toFixed(2) + '小时';
                            callback(ticket, res);
                            return res;
                        }
                    },
                    legend: {
                        data: ['升降机左笼', '升降机右笼'],
                        x: 'right',
                        orient: 'vertical'
                    },
                    xAxis: [{
                        type: 'category',
                        axisLabel: {
                            interval: 0
                        },
                        data: dateX
                    }],
                    yAxis: [{
                        type: 'value'
                    }],
                    series: [{
                        name: '升降机右笼',
                        type: 'bar',
                        barWidth: 20,
                        stack: '总量',
                        itemStyle: { // 系列级个性化
                            normal: {
                                color: 'rgba(243,226,0,0.5)'//工程黄
                            }
                        },
                        data: dateY2
                    }, {
                        name: '升降机左笼',
                        type: 'bar',
                        barWidth: 20,
                        stack: '总量',
                        itemStyle: { // 系列级个性化
                            normal: {
                                color: 'rgba(135,206,235,0.5)'//天蓝
                            }
                        },
                        data: dateY1
                    }]
                };
                myChart2.setOption(option2);
            });
        } else {
            callSvr("eqpt/getRunTimeList", {"eqptId": em.EqptId, "type": em.EqptType}, function (result) {
                var dateX = result.date;
                var dateY1 = result.runTime1;
                var option2 = {
                    title: {
                        text: '塔机上/断电时间统计',
                        textStyle: {
                            align: 'left',
                            fontFamily: '微软雅黑',
                            fontSize: 14
                        }
                    },
                    grid: {
                        x: '9%',
                        y: '15%',
                        x2: '7%',
                        y2: '15%'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        },
                        formatter: function (params, ticket, callback) {
                            var res = '日期:' + params[0].name;
                            var sum = 0.0;
                            for (var i = 0, l = params.length; i < l; i++) {
                                res += '<br/>' + params[i].seriesName + ' : '
                                        + params[i].value + '小时';
                            }
                            callback(ticket, res);
                            return res;
                        }
                    },
                    legend: {
                        data: ['上/断电时间'],
                        x: 'right',
                        orient: 'vertical'
                    },
                    xAxis: [{
                        type: 'category',
                        axisLabel: {
                            interval: 0
                        },
                        data: dateX
                    }],
                    yAxis: [{
                        type: 'value'
                    }],
                    series: [{
                        name: '上/断电时间',
                        type: 'bar',
                        barWidth: 20,
                        itemStyle: { // 系列级个性化
                            normal: {
                                color: 'rgba(135,206,235,0.5)'//天蓝
                            }
                        },
                        data: dateY1
                    }]
                };
                myChart2.setOption(option2);
            });
        }

    }
    function RealWorking(ele, termCode, tbodyID, intType, litDivId) {
        if ($(ele).attr("data-status") == 0) {
            $(ele).html("停止实时工况").attr("data-status", 1);
            if (!(termCode == "undefined" || termCode == "" || termCode == "-")) {
                if (intType == "crane" || intType == "lifter_l") {
                    int = new IntRealWorking(termCode, em.EqptType, tbodyID, litDivId);
                    int.start();
                } else {
                    int1 = new IntRealWorking(termCode, em.EqptType, tbodyID, litDivId);
                    int1.start();
                }
            }
        } else {
            $(ele).html("查看实时工况").attr("data-status", 0);
            if (intType == "crane" || intType == "lifter_l") {
                if (typeof(int) != "undefined")int.stop();
            } else {
                if (typeof(int1) != "undefined")int1.stop();
            }
        }
    }
</script>